The R Spatial Ecosystem

A few main packages are dedicated to spatial data handling like import/export, display, geoprocessing, spatial ststistics.

“Historical” Packages

These packages are still widely used.

Simple Features for R

  • sp, rgeos and rgdal functionnalities in one package.

  • Easier data handling, simpler objects.

  • Main author and maintainer: Edzer Pebesma (also sp author)

  • Compatibility with the pipe synthax and tidyverse operators.

  • First release: October 20, 2016

  • Website: Simple Features for R


sf objects data structure:

format sf

Using sf

Data Import

Reading layer `martinique' from data source `C:\Users\Kim Antunez\Documents\Projets_R\Geovisualisation\flo\data\mtq\martinique.shp' using driver `ESRI Shapefile'
Simple feature collection with 34 features and 23 fields
geometry type:  POLYGON
dimension:      XY
bbox:           xmin: 690574.4 ymin: 1592426 xmax: 736126.5 ymax: 1645660
epsg (SRID):    32620
proj4string:    +proj=utm +zone=20 +datum=WGS84 +units=m +no_defs

Data Display

Default

Only geometry

Distance Matrix

Units: m
          [,1]     [,2]      [,3]      [,4]      [,5]
[1,]     0.000 35297.56  3091.501 12131.617 17136.310
[2,] 35297.557     0.00 38332.602 25518.913 18605.249
[3,]  3091.501 38332.60     0.000 15094.702 20226.198
[4,] 12131.617 25518.91 15094.702     0.000  7177.011
[5,] 17136.310 18605.25 20226.198  7177.011     0.000

Maps with R

Several solutions are available:

  • ggplot2 users can have a look to ggplot2 mapping features (geom_sf) that can mix nicely with ggspatial.
  • For more advanced mapping features in a ggplot2-like syntax have a look to tmap
  • cartography is based on base graphics and allow most of basic and advanced cartographic representations. Full disclosure: the speaker is the maintainer of cartography.

Here we will focus on cartography and do small examples with ggplot2.

cartography

Data Preparation

Reading layer `seine_maritime' from data source `C:\Users\Kim Antunez\Documents\Projets_R\Geovisualisation\flo\data\rhone\seine_maritime.geojson' using driver `GeoJSON'
Simple feature collection with 718 features and 1 field
geometry type:  MULTIPOLYGON
dimension:      XY
bbox:           xmin: 0.06560943 ymin: 49.25139 xmax: 1.790225 ymax: 50.07121
epsg (SRID):    4326
proj4string:    +proj=longlat +datum=WGS84 +no_defs
Reading layer `dep' from data source `C:\Users\Kim Antunez\Documents\Projets_R\Geovisualisation\flo\data\rhone\dep.geojson' using driver `GeoJSON'
Simple feature collection with 96 features and 2 fields
geometry type:  MULTIPOLYGON
dimension:      XY
bbox:           xmin: -5.138996 ymin: 41.36216 xmax: 9.559598 ymax: 51.089
epsg (SRID):    4326
proj4string:    +proj=longlat +datum=WGS84 +no_defs

Exploration of sirene & osm db for restaurants

CRAN Task View: Analysis of Spatial Data

See file data_prep.R for data extraction.

Count Points in Units

Interactive Visualisation

Explore datasets interactively

The default is not bad:

mapview allow hightly customizable maps:

These maps, as appealing as they seem to be, are not really suitable for displaying geostatistical info. For data exploration they are really useful.



reproducibility

R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252   
[3] LC_MONETARY=French_France.1252 LC_NUMERIC=C                  
[5] LC_TIME=French_France.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] mapview_2.4.0       maptools_0.9-2      raster_2.6-7       
 [4] sp_1.3-1            spatstat_1.56-1     rpart_4.1-13       
 [7] nlme_3.1-137        spatstat.data_1.3-1 ggplot2_3.0.0      
[10] cartography_2.1.1   sf_0.6-3            rmdformats_0.3.3   
[13] knitr_1.20         

loaded via a namespace (and not attached):
 [1] viridisLite_0.3.0    foreach_1.4.4        R.utils_2.6.0       
 [4] shiny_1.1.0          assertthat_0.2.0     stats4_3.5.1        
 [7] highr_0.7            yaml_2.2.0           pillar_1.2.3        
[10] backports_1.1.2      lattice_0.20-35      glue_1.3.0          
[13] digest_0.6.15        promises_1.0.1       polyclip_1.9-1      
[16] colorspace_1.3-2     htmltools_0.3.6      httpuv_1.4.4.1      
[19] Matrix_1.2-14        R.oo_1.22.0          plyr_1.8.4          
[22] pkgconfig_2.0.1      questionr_0.6.3      bookdown_0.7        
[25] purrr_0.2.5          xtable_1.8-2         webshot_0.5.0       
[28] scales_0.5.0         tensor_1.5           satellite_1.0.1     
[31] later_0.7.3          spatstat.utils_1.9-0 tibble_1.4.2        
[34] mgcv_1.8-24          withr_2.1.2          lazyeval_0.2.1      
[37] gdalUtils_2.0.1.14   magrittr_1.5         mime_0.5            
[40] deldir_0.1-15        evaluate_0.11        R.methodsS3_1.7.1   
[43] foreign_0.8-70       class_7.3-14         tools_3.5.1         
[46] formatR_1.5          stringr_1.3.1        munsell_0.5.0       
[49] bindrcpp_0.2.2       compiler_3.5.1       e1071_1.6-8         
[52] rlang_0.2.1          classInt_0.2-3       units_0.6-0         
[55] grid_3.5.1           iterators_1.0.10     rstudioapi_0.7      
[58] htmlwidgets_1.2      goftest_1.1-1        crosstalk_1.0.0     
[61] miniUI_0.1.1.1       base64enc_0.1-3      labeling_0.3        
[64] rmarkdown_1.10       gtable_0.2.0         codetools_0.2-15    
[67] abind_1.4-5          DBI_1.0.0            R6_2.2.2            
[70] dplyr_0.7.6          rgdal_1.3-3          rgeos_0.3-28        
[73] bindr_0.1.1          rprojroot_1.3-2      stringi_1.1.7       
 [ reached getOption("max.print") -- omitted 6 entries ]